<template>
  <!--系统消息-->
  <div class="statistics-container">
    <vab-query-form>
      <vab-query-form-left-panel :span="8">
        <el-button type="primary" @click="add()">添加系统消息</el-button>
      </vab-query-form-left-panel>
      <vab-query-form-right-panel :span="16">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.keyword"
              style="margin-right: 10px"
              placeholder="请输入用户名或手机号"
              clearable
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="search()">
              查询
            </el-button>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-refresh-right"
              @click="restart"
            >
              重置
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table
      v-loading="listLoading"
      :data="list"
      @selection-change="setSelectRows"
    >
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="序号"
        sortable
        type="index"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="appid_info.mobile"
        label="手机号"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="appid_info.nickname"
        label="昵称"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="create_time"
        label="发布时间"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="content.msg"
        label="内容"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="status"
        label="状态"
      >
        <template #default="{ row }">
          {{ row.status == 1 ? '已查看' : row.status == 2 ? '未查看' : '' }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template #default="{ row }">
          <el-button type="text" @click="del(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 弹窗 -->
    <el-dialog :title="wintit" :visible.sync="dialogFormVisible">
      <div>
        <el-input
          v-model="message"
          type="textarea"
          placeholder="请输入消息内容"
          rows="10"
        />
        <el-button type="primary" class="adds" @click="send">发布</el-button>
      </div>
    </el-dialog>

    <el-pagination
      background
      :current-page="queryForm.page"
      :page-size="queryForm.list_row"
      :layout="layout"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
  import {
    getSystemMsgLists,
    sendSystemMsgs,
    delSystemMsgs,
  } from '@/api/common'

  export default {
    name: 'User',
    data() {
      return {
        queryForm: {
          page: 1,
          list_row: 10,
          keyword: '',
        },
        listLoading: false,
        wintit: '',
        list: [
          {
            title: '名称',
            user: '张三',
            to: '李四',
            statu: 1,
            create_time: '2021-01-01 12:01',
            back_time: '2021-01-08 12:01',
          },
        ],
        labels: [],
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        dialogFormVisible: false,
        message: '',
      }
    },
    created() {
      this.getData()
    },
    methods: {
      handleDetail() {},
      restart() {
        this.queryForm = []
        this.getData()
      },
      //搜索
      search() {
        this.getData()
      },
      getData() {
        let params = {
          page: this.queryForm.page,
          limit: this.queryForm.list_row,
          search_input: this.queryForm.keyword,
        }
        getSystemMsgLists(params).then((data) => {
          this.list = data.data
          this.total = data.count
        })
      },
      add() {
        this.dialogFormVisible = true
        this.wintit = '发布系统消息'
      },
      send() {
        let params = {
          type: '0',
          data: this.message,
        }
        sendSystemMsgs(params).then((data) => {
          this.dialogFormVisible = false
          this.$message.success('发布成功！')
          this.getData()
        })
      },
      del(row) {
        let params = {
          id: row.id,
        }
        delSystemMsgs(params).then((data) => {
          this.$message.success('删除成功！')
          this.getData()
        })
      },
      setSelectRows() {},
      handleSizeChange(val) {
        this.queryForm.list_row = val
        this.getData()
      },
      handleCurrentChange(val) {
        this.queryForm.page = val
        this.getData()
      },
    },
  }
</script>

<style lang="scss" scoped>
  .el-button {
    font-size: 14px;
    margin-right: 20px;
    &.adds {
      width: 100%;
      margin-top: 20px;
    }
  }
</style>
